package pers.xiaojun.boot.module.system.controller.oauth2;

import cn.hutool.core.bean.BeanUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pers.xiaojun.boot.common.pojo.CommonResult;
import pers.xiaojun.boot.module.system.controller.oauth2.vo.OAuth2UserRespVO;
import pers.xiaojun.boot.module.system.dao.entity.user.AdminUserDO;
import pers.xiaojun.boot.module.system.service.user.UserService;
import pers.xiaojun.boot.security.util.SecurityUtils;

/**
 * OAuth 2.0 用户信息接口
 *
 * @author xiaojun
 * @since 2025-10-21
 */
@Tag(name = "OAuth 2.0 用户信息")
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/oauth2/user")
public class OAuth2UserController {

    private final UserService userService;


    @Operation(summary = "获取授权用户公开信息")
    @GetMapping("/public")
    @PreAuthorize("@ss.hasAnyScopes('user_public:read')")
    public CommonResult<OAuth2UserRespVO> getUserInfo() {
        AdminUserDO user = userService.getById(SecurityUtils.getUserId());
        OAuth2UserRespVO userResp = BeanUtil.toBean(user, OAuth2UserRespVO.class);
        return CommonResult.success(userResp);
    }

}
